//
//  main.c
//  C_6结构联合和位字段
//
//  Created by Robin on 16/3/17.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>

// 结构
struct excise {
    const char *description;
    float duration;
};

struct meal {
    const char *food;
    float weight;
};

struct preferences {
    struct excise exercise;
    struct meal meal;
};

struct fish {
    const char *name;
    const char *species;
    float age;
    int teeth;
    struct preferences hobby;
};

typedef struct {
    const char *name;
    const char *species;
    float age;
}turtle;

// 联合
typedef union {
    float weight;
    float vloume;
    int   count;
}quantity;

void happy_birthday (turtle *t);
void catalog (struct fish f);

int main(int argc, const char * argv[]) {
    
//    struct fish Snappy = {"snappy","piranha",3,64,{{"swim in pool",7.5},{"Meat",4.5}}};
//    
//    //printf("snappy like %s\n",Snappy.hobby.food);
//    printf("snappy excise %s\n",Snappy.hobby.exercise.description);
//    
//
//    turtle t = {"Myrtle","SeaTurtle",99};
//
//    happy_birthday(&t);
//    
//    printf("turtle age is %f\n",t.age);
    
    
    quantity m = {4};
    quantity q = {.count=9};
//    q.weight = 1.08;

    printf("q count is %i q weight is %0.2f\n",q.count,q.weight);
    return 0;
}


void happy_birthday (turtle *t){
    
    (*t).age = (*t).age + 1;
}

void catalog (struct fish f){
    printf("%s is a %s with %i.He is %f\n",f.name,f.species,f.teeth,f.age);
}
